Skip to content

Fixes #38245: Close push feed sockets without a session when their token expires or their user is deleted - #38876

Open
Vamsi-klu wants to merge 4 commits into
open-metadata:mainfrom
Vamsi-klu:fix/38245-sessionless-socket-lifetime
Open

Vamsi-klu wants to merge 4 commits into
open-metadata:mainfrom
Vamsi-klu:fix/38245-sessionless-socket-lifetime

Conversation

@Vamsi-klu

@Vamsi-klu Vamsi-klu commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #38245

A push feed socket opened with a token that carries no session (a public client SSO provider token, a bot token, a personal access token) was trusted on that token's validation, once, at the upgrade, and never checked again. It stayed open after the token expired and after its user was deleted, until the client left or the server restarted.

Root cause (lines on main at 1971feb):

  1. SocketAddressFilter.validateCookielessHandshake accepts such a handshake on the token alone (SocketAddressFilter.java:269), and validatePrefixedTokenRequest (:313) keeps only the user name and session claim from the verified claims. The exp is thrown away.
  2. HandshakeIdentity (HandshakeIdentity.java:23) had nowhere to carry an expiry, so nothing about it reached the socket on either transport.
  3. The sweep, WebSocketManager.disconnectInactiveSessions (WebSocketManager.java:307), looks only at sockets with a session id (:319), so it skipped these sockets entirely.
  4. Revocation closes sockets by session (OpenMetadataApplication.wireSessionRevocationToWebSockets, :1216, publishing at :1232). Deleting a user goes through UserRepository.revokeLiveSessions (UserRepository.java:1839) and SessionService.revokeSessionsForUser (SessionService.java:738), which finds zero sessions for a user who signed in with a provider token, so none of their sockets closed. disconnectAllForUser (WebSocketManager.java:250) existed, and peers already answer a revoke without a session id with it (CacheBundle.java:125), but nothing published one.
  5. Only the websocket transport is affected, and it is the only one the UI uses (WebSocketProvider.tsx:128). Polling requests go through the filter on every request and get a 401 once the token expires.

The fix

  • The handshake keeps the verified exp and stamps it as a server owned TokenExpiresAt header (epoch milliseconds), on both transports, only when it accepted the socket without a session. A client's own copy of that header is always dropped. A socket with a session is still governed by its session, which the sweep already rechecks.
  • The existing sweep closes such a socket at its first pass after exp, using the same strict comparison and zero leeway as JwtFilter. Right before closing it sends tokenExpiredChannel to that socket. A stamped value the server cannot read counts as expired.
  • Deleting a user, soft or hard, now ends all of their sockets. The UserRepository.beginDeleteLifecycle closure, which every delete path runs (including the bulk soft delete of a bot's user that skips postDelete), calls WebSocketManager.endAccessForUser. That closes the user's sockets on this server and publishes session/revoke with the user id and no session id, which peers on main already handle.
  • Each sweep also asks whether a user holding a socket without a session still exists (PushFeedUserPresence, a cached lookup) and closes all their sockets if not. A failed lookup is not a deletion: the sockets stay and the next pass asks again. This covers peers without Redis, tokens with no exp, and a handshake validated just before the delete that registers after it.
  • UI: WebSocketProvider retries a server close only when tokenExpiredChannel came first, reading the current token (the app renews it about 60 s before exp). Every other server close is still final, so the rule in the ADR "A refresh ends sessions issued by a provider that is no longer configured" holds. Without this, every public client SSO tab would lose push once per provider token lifetime.
  • CacheInvalidationPubSub gets TYPE_SESSION and OP_REVOKE constants; CacheBundle and the revocation listener use them. No behavior change there.

Bound: a socket without a session closes at most one sweep interval after exp (60 s by default, 15 s at least, WEBSOCKET_SESSION_VALIDATION_INTERVAL_SECONDS). After a user delete it closes at once on the server that ran the delete and on Redis peers, and within one interval plus the 30 s entity cache on peers without Redis.

Unchanged on purpose: sockets with a session are not bounded by their access token's exp (basic and confidential tabs would drop every hour). Tokens without exp (an Unlimited bot token or personal access token) get no expiry bound, the same as on REST; deletion, a provider switch and a restart still end them. isSessionActiveForUser keeps its predicate, which is what #38247 changes.

No tokens are logged. The new close logs carry only the user id and socket id.

Type of change:

  • Bug fix

High level design:

Approach. Reuse the sweep that already runs every interval rather than adding a timer per socket. The expiry is stamped where the identity is already stamped (SocketAddressFilter.stampIdentity for polling, Jetty12WebSocketHandler.stampValidatedIdentity for the upgrade); the header names now live once on HandshakeIdentity. WebSocketManager takes a PushFeedSocketPolicy (the applied provider, a clock, the user presence check and the peer notifier); the existing builder overloads stay and default to "no user is gone, no peer is told". The per socket expiry lives in SocketTokenExpiries, one entry per registered socket, removed on every disconnect path through one forgetSocket. It is a registry bounded by live connections, not a cache, so the cache size rule in AGENTS.md does not apply.

Alternatives rejected.

  • A timer per socket at exp: a new executor and cancellation bookkeeping, and pending tasks for 90 day tokens. The sweep bound matches the staleness the multi node design already accepts.
  • Full token validation on every sweep: RSA, JWKS and credential reads per socket per pass, and a transient IdP or DB error would mass close sockets the UI does not reopen.
  • Hooking postDelete: the bulk bot user delete skips it.
  • Closing all sockets inside revokeSessionsForUser: a password change also calls it, and personal access token and bot sockets must survive that.
  • A new relay scope for the delete signal: a new contract between pods, while the existing revoke without a session id already does the job.
  • Rejecting bot tokens and personal access tokens at the handshake: it would break API clients.

Compatibility and rollout.

  • Behavior change: a client holding a provider token, or a bot token or personal access token with an exp, is disconnected up to one interval after exp. Public client SSO tabs reconnect on their own thanks to the UI change; other clients must reconnect after tokenExpiredChannel. Deleted users lose their sockets at once.
  • An old UI against a new server ignores the new event, so such a tab drops push after its token expires until a reload. Worth a line in the release notes.
  • Rolling upgrade: the header is local to the pod, and the pubsub message shape already exists and old pods already handle it.
  • No new flag, no migration, no schema change, so MySQL and Postgres are unaffected.
  • Collate: public signatures are kept (the three argument HandshakeIdentity constructor, both WebSocketManagerBuilder.build overloads, validatePrefixedTokenRequest, disconnectInactiveSessions). I could not grep the Collate repository from here, so a Collate check for HandshakeIdentity( and WebSocketManagerBuilder.build is still worth doing.

Decision records. New ADR "A push feed socket without a session ends when its token expires or its user is deleted", and a v2 amendment to "Push feed socket handshakes are always authenticated" saying that trust in a token without a session lasts until its exp. The multi node session design doc (sections 8.2, 8.3, 8.4, 10.3 and 11) is updated to match.

Tests:

Use cases covered

  • A public client SSO socket closes after its provider token expires, gets tokenExpiredChannel first, and another user's socket with a valid token stays open.
  • Soft deleting a user closes their socket right away (well under one sweep) and leaves other users' sockets alone.
  • A restored user's old socket stays closed and a new socket connects.
  • Hard deleting a user closes their socket right away.
  • A socket opened with a personal access token on one node closes when its user is deleted through the other node.
  • The UI reconnects with the renewed token after the notice, only once, and still does not retry any other server close.

These tests fail on main (run against the test commit, before the fix):

  • WebSocketManagerTest: disconnectInactiveSessions_closesASessionlessSocketOnceItsTokenHasExpired, disconnectInactiveSessions_sendsTheTokenExpiredNoticeBeforeClosing, onConnection_treatsAMalformedExpiryAsExpired
  • OpenMetadataApplicationAuthReloadTest.buildPushFeedSockets_closesEverySocketOfAUserWhoIsGone
  • SocketAddressFilterTest: providerTokenHandshakeWithoutSessionIsStampedWithItsExpiry, clientSentTokenExpiresAtHeaderIsDropped, upgradeHandlerStampsTheValidatedExpiryAndDropsTheClientsCopy
  • Jetty12WebSocketHandlerTest.clientTokenExpiryHeaderIsDroppedBeforeStamping
  • WebSocketProvider.test.tsx: the reconnect after the token expired notice, and the single retry per notice
  • SsoPushFeedSocketIT and SessionMultiNodeIT.pushFeedSocketOpenedWithAPersonalAccessTokenClosesWhenItsUserIsDeletedOnAnotherNode (see the results comment)

The tests that need the new API (the hand moved clock cases, endAccessForUser, PushFeedUserPresenceTest, publishUserAccessEnded) are in the fix commit, since they cannot compile on main.

Unit tests

  • I added unit tests for the new and changed logic.

  • Files added or updated: WebSocketManagerTest, SocketAddressFilterTest, Jetty12WebSocketHandlerTest, PushFeedUserPresenceTest (new), OpenMetadataApplicationAuthReloadTest, WebSocketProvider.test.tsx. The clock tests use a hand moved Clock, no sleeps.

  • Coverage from the unit run (jacoco, with the static code analysis profile): PushFeedUserPresence, PushFeedSocketPolicy, SocketTokenExpiries and HandshakeIdentity 100%, SocketAddressFilter 94%, WebSocketManager 88% overall. Of the lines this PR changes in WebSocketManager, SocketAddressFilter and Jetty12WebSocketHandler, all are covered except the two connect_error and connect_failed log lambdas that moved unchanged into listenForClose. The uncovered lines elsewhere in WebSocketManager and Jetty12WebSocketHandler are untouched relay and transport code. The UserRepository hook is covered by SsoPushFeedSocketIT.

Backend integration tests

  • I added integration tests in the integration tests module.
  • Files added or updated: SsoPushFeedSocketIT (new), SessionMultiNodeIT (one new method), PushFeedSocket (new helper, a socket.io client opened the way the UI opens one), MockOidcProvider and MockOidcTokens (an ID token with a chosen lifetime).
  • The new IT class names match the existing *Sso*IT and *Feed*IT patterns and socket/** is already owned, so the impact map needed no change (the branch check in the local test planner is clean).
  • Local results are in a PR comment.

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable. The UI change is a reconnect rule inside WebSocketProvider, covered by its Jest test; nothing on screen changes.

Manual testing performed

  1. Ran the unit and Jest suites above on the test commit (red) and on the fix (green).
  2. Ran SsoPushFeedSocketIT and the new SessionMultiNodeIT method against the test commit to see them fail, then the IT scope in the PR comment against the fix.
  3. Checked in socket.io server 4.1.2 and engine.io server 6.3.2 that the notice and the DISCONNECT packet go through the same ordered write buffer, and that a close waits for that buffer to drain, so the client sees the notice before the disconnect. PF 01 asserts that order on a real socket.

UI screen recording:

Not applicable: this is a bug fix with no visible UI change. The UI part only decides whether to reconnect a socket after one specific server close.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes #38245: <short explanation>
  • My PR is linked to a GitHub issue via Fixes #38245 above.
  • I have commented on my code, particularly in hard to understand areas.
  • For JSON Schema changes: not applicable, no schema change.
  • For a UI feature or feature task: not applicable, explained above.
  • I have added tests (unit, integration, Jest) and listed them above.
  • Self review: I reviewed the final diff against REVIEW.md.
  • Decision check: this PR adds a record under the decisions folder and amends one.
  • I have added a test that covers the exact scenario we are fixing, and the tests reference Push-feed sockets opened with a provider token and no session are never revalidated #38245.

Related

These tests fail on main. A socket opened with a token that carries no
session is never closed when that token expires or when its user is
deleted, the handshake never stamps the token expiry, and the UI never
retries a server close.
… delete

A socket accepted on a token that carries no session now keeps the
token's exp, stamped by the handshake on both transports. The sweep
closes it at its first pass after exp and sends tokenExpiredChannel
first. Deleting a user closes all of that user's sockets on this server
and tells the peers, and the sweep also closes the sockets of a user who
no longer exists, which covers peers without Redis.
…expired

The server now sends tokenExpiredChannel right before it closes a socket
opened without a session at its token's exp. The UI retries only that
close, with the token it holds now, which it renewed before exp. Every
other server close stays final.
…gn doc

Adds the decision record for sockets without a session, amends the
record on push feed handshakes to say that trust in such a token lasts
until its exp, and updates the multi node session design to match.
@Vamsi-klu
Vamsi-klu requested review from a team as code owners November 26, 2026 14:21
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@Vamsi-klu

Copy link
Copy Markdown
Contributor Author

Local test results for this PR. PR CI runs only the Java unit tests, so the integration tests below were run on my machine.

Unit tests, on the test commit before the fix (red)

WebSocketManagerTest, SocketAddressFilterTest, SocketAddressFilterSpoofRevalidationBypassTest, Jetty12WebSocketHandlerTest, OpenMetadataApplicationAuthReloadTest: 77 run, 8 failed, all of them the new regression tests, each for the reason it was written for:

  • WebSocketManagerTest.disconnectInactiveSessions_closesASessionlessSocketOnceItsTokenHasExpired: the socket whose token expired a second earlier was never closed.
  • WebSocketManagerTest.disconnectInactiveSessions_sendsTheTokenExpiredNoticeBeforeClosing: no notice and no close.
  • WebSocketManagerTest.onConnection_treatsAMalformedExpiryAsExpired: the socket stayed open.
  • OpenMetadataApplicationAuthReloadTest.buildPushFeedSockets_closesEverySocketOfAUserWhoIsGone: the sweep never looked at the deleted user's socket.
  • SocketAddressFilterTest.providerTokenHandshakeWithoutSessionIsStampedWithItsExpiry: expected the token's exp, got no header.
  • SocketAddressFilterTest.clientSentTokenExpiresAtHeaderIsDropped: the client's own TokenExpiresAt reached the servlet.
  • SocketAddressFilterTest.upgradeHandlerStampsTheValidatedExpiryAndDropsTheClientsCopy: the upgrade stamped no expiry and kept the client's copy.
  • Jetty12WebSocketHandlerTest.clientTokenExpiryHeaderIsDroppedBeforeStamping: the client's header survived the upgrade.

Jest, WebSocketProvider.test.tsx: 10 run, 2 failed (the reconnect after the token expired notice, and the one retry per notice); the 8 existing tests passed.

Integration tests on the test commit (MySQL and Elasticsearch, global state lane), only the new ones: SsoPushFeedSocketIT (4) and SessionMultiNodeIT.pushFeedSocketOpenedWithAPersonalAccessTokenClosesWhenItsUserIsDeletedOnAnotherNode (1). 5 run, 5 failed, each by timing out waiting for a close that never came:

  • PF 01: the socket whose provider token expired was still open after one sweep interval, the token lifetime and a 30 s margin.
  • PF 02, PF 03, PF 04: after a soft delete, a delete before restore, and a hard delete, the user's socket was still open after 10 s.
  • The multi node case: the socket opened with a personal access token on node B was still open a minute after its user was deleted through node A.

With the fix (green)

Unit tests, on the fix: WebSocketManagerTest (30), SocketAddressFilterTest (32), SocketAddressFilterSpoofRevalidationBypassTest (3), Jetty12WebSocketHandlerTest (9), PushFeedUserPresenceTest (3), OpenMetadataApplicationAuthReloadTest (14), UserRepositoryUnitTest (3), JwtFilterTest (106), CacheBundleTest (4), FeedServletTest (2), HeaderRequestWrapperTest (6): 212 run, 0 failed (the last test I added to WebSocketManagerTest ran in a final rerun of the socket classes, 88 run, 0 failed). OAuthHttpStatelessServerTransportProviderTest in the MCP module, which calls validatePrefixedTokenRequest: 43 run, 0 failed.

Jest, WebSocketProvider.test.tsx: 10 run, 0 failed.

Integration tests on the fix, first pass:

  • MySQL and Elasticsearch, global state lane, SsoPushFeedSocketIT, SsoOidcPublicBearerIT, the new SessionMultiNodeIT method and SsoTokenRenewalIT in one fork: SsoPushFeedSocketIT 4 of 4 passed, SsoOidcPublicBearerIT 14 of 14 passed, the SessionMultiNodeIT method passed. SsoTokenRenewalIT failed 15 of 15 at login with a 500 from /api/v1/auth/login, because the main server was answering with the basic auth handler instead of the OIDC one. That was my run, not the change: I put SessionMultiNodeIT in the same fork, and its extra nodes replace the JVM wide auth singletons for every suite that runs after them (CI keeps it in its own multi node lane). The second pass below reruns it on its own.
  • Redis cache lane, SessionRedisMultiNodeIT (which covers the pubsub path to peers): 8 of 8 passed.

One more caveat about that first pass: a test harness class compiled from an early draft of mine (which I dropped before the first commit) set the server's sweep interval to 15 s, so the red run and this first pass swept every 15 s instead of 60 s (that only shortened the red waits). Sweeping more often is the stricter case for "does not close the wrong sockets", but CI runs at 60 s, so the second pass recompiles the harness and runs at the default.

Integration tests on the fix, second pass (MySQL and Elasticsearch, global state lane, harness recompiled, server at the default 60 s sweep, no multi node suite in the fork): SsoPushFeedSocketIT 4 of 4 passed (PF 01 in 23.6 s, PF 02 in 5.5 s, PF 03 in 2.3 s, PF 04 in 2.3 s) and SsoTokenRenewalIT 15 of 15 passed.

In total on the fix: SsoPushFeedSocketIT 4 of 4 (twice), SsoOidcPublicBearerIT 14 of 14, SsoTokenRenewalIT 15 of 15, the new SessionMultiNodeIT method 1 of 1, SessionRedisMultiNodeIT 8 of 8.

PF 01 also asserts the order the client saw: tokenExpiredChannel first, then io server disconnect, which is what the UI change relies on.

One thing the multi node case cannot show: the nodes of the in process test cluster share one push feed socket registry, so that test proves the close across the nodes' endpoints, but not the sweep on a peer without Redis. That path is covered by OpenMetadataApplicationAuthReloadTest.buildPushFeedSockets_closesEverySocketOfAUserWhoIsGone and the WebSocketManagerTest sweep tests.

Other checks

  • mvn spotless:apply on the service and integration test modules, and the UI checkstyle sequence (organize imports, ESLint, Prettier) on the changed UI files: no diff left.
  • Decision record check: clean. Impact map branch check: the branch leaves the map complete.

@gitar-bot

gitar-bot Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved 🔴 High risk

Enforcing token expiry and user deletion for sessionless push-feed sockets changes ongoing access control; missed revocation could leave deleted users receiving feed data.

Closes push feed sockets opened without a session once their token expires or their user is deleted, via a TokenExpiresAt stamp checked by the existing sweep, a session/revoke publish on user delete, and a UI reconnect only after tokenExpiredChannel. No open issues found.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Push-feed sockets opened with a provider token and no session are never revalidated

2 participants